import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'lib-flexible'
import QMP from '@/plugins/qmp-ui'
import './assets/styles/qmp-ui.less'
import { DevConfig, nativeHandler, judgeSys } from 'qmp-native'
import { getCookieToken } from '@/utils/auth'
import { Toast, Dialog } from 'qmp-component'
import { SimpleEvents } from '@/utils'

const app = createApp(App)

// 添加全局方法
app.config.globalProperties.$nativeHandler = nativeHandler
app.config.globalProperties.$judgeSys = judgeSys
app.config.globalProperties.$toast = Toast
app.config.globalProperties.$dialog = Dialog
app.config.globalProperties.$SimpleEvents = SimpleEvents

console.log(process.env)

if (process.env.QMP_EVN === 'development') {
  DevConfig.useDefaultData = true // 开发环境调用原生方法时，使用是否使用默认数据
  // 开发环境默认数据配置
  DevConfig.defaultData = {
    '': {
      token: `Bearer ${getCookieToken()}`
    },
    // nativeHandler('getBaseInfo') 接口在测试环境返回的数据
    getBaseInfo: {
      account: 'songdanmei',
      userName: '宋丹妹',
      gender: 0,
      phone: '18284533619',
      photo: null,
      pinyin: 'songdanmei',
      proDateEnd: null,
      source: 'PLATFORM',
      staffCode: 'QY-00074449',
      userId: '6c709d50-068c-47f9-b09d-50068c07f99d',
      userType: 1,
      alternatePhone: '',
      appOrganizationDTOList: [
        { orgId: 'edb1a9f5-d74c-456d-b1a9-f5d74c556d19', orgName: '辽吉黑独资办事处' },
        { orgId: 'b78ff00d-cafe-11ea-a548-005056ad7722', orgName: '营销信息科' },
        { orgId: 'b78f9255-cafe-11ea-a548-005056ad7722', orgName: '辽宁办事处' }
      ],
      appPositionDTOList: [
        {
          positionCode: 'top_0',
          positionDesc: '',
          positionId: 'a19f08ac-5837-4b0b-9f08-ac5837bb0b37',
          positionName: '经销商用户'
        },
        {
          positionCode: 'khjl_dz',
          positionDesc: '',
          positionId: 'f59be935-7966-4714-9be9-357966f71484',
          positionName: '定制客户经理'
        }
      ],
      appRoleDTOList: [
        {
          roleCode: '1606553685790',
          roleDesc: null,
          roleId: '0573339d-d215-4194-b333-9dd21531941a',
          roleName: 'CTM-档案科'
        },
        {
          roleCode: '1595933457788',
          roleDesc: null,
          roleId: '0867c49b-338d-4348-a7c4-9b338d434877',
          roleName: 'CTM-客户经理角色1'
        }
      ]
    },
    // 调用原生其他接口 返回的数据
    default: {
      property1: 'value1',
      property2: 'value2'
    }
  }
}

// 注册qmp-ui组件
const qmpComponents = [...QMP.components]
qmpComponents.forEach((i) => app.use(i))
app.use(store).use(router).mount('#app')

// 自定义路由返回方法（用于实现返回页面过渡动画）
router.goBack = () => {
  router.isBack = true
  window.history.go(-1)
}
